/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('aquila', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model DoInferenceRequest {
  body?: map[string]any(name='body'),
}

model DoInferenceResponseBody = {
  code?: long(name='Code'),
  data?: {
    risk?: string(name='Risk'),
  }(name='Data'),
  requestId?: string(name='RequestId'),
}

model DoInferenceResponse = {
  headers: map[string]string(name='headers'),
  body: DoInferenceResponseBody(name='body'),
}

async function doInference(request: DoInferenceRequest): DoInferenceResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return doInferenceWithOptions(request, headers, runtime);
}

async function doInferenceWithOptions(request: DoInferenceRequest, headers: map[string]string, runtime: Util.RuntimeOptions): DoInferenceResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.body)) {
    body['body'] = request.body;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DoInference',
    version = '2020-01-04',
    protocol = 'HTTPS',
    pathname = `/nlp-filter/v3190/nlp_filter`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model DoIntentionRequest {
  body?: map[string]any(name='body'),
}

model DoIntentionResponse = {
  headers: map[string]string(name='headers'),
  body: object(name='body'),
}

async function doIntention(request: DoIntentionRequest): DoIntentionResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return doIntentionWithOptions(request, headers, runtime);
}

async function doIntentionWithOptions(request: DoIntentionRequest, headers: map[string]string, runtime: Util.RuntimeOptions): DoIntentionResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.body)) {
    body['body'] = request.body;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'DoIntention',
    version = '2020-01-04',
    protocol = 'HTTPS',
    pathname = `/intention/v7918/intention`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

